package com.fmjava.controller;

import com.fmjava.ServiceImpl.EmployeeServiceImpl;
import com.fmjava.ServiceImpl.FocusserviceImpl;
import com.fmjava.ServiceImpl.NewsServiceImpl;
import com.fmjava.domain.Focus;
import com.fmjava.domain.News;
import com.fmjava.domain.PageBean;
import com.fmjava.service.EmployeeService;
import com.fmjava.service.Focusservice;
import com.fmjava.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/HomePageServlet")
public class HomePageServlet extends HttpServlet {
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Focusservice focusservice=new FocusserviceImpl();
//        焦点轮播图
        List<Focus> focus=focusservice.getAllFocus();
        request.setAttribute("focus",focus);
//        用户
        EmployeeService employeeService = new EmployeeServiceImpl();
        request.setAttribute("employees", employeeService.getAllEmployeeUsers());
//        公告类
        request.setCharacterEncoding("utf-8");
        request.setAttribute("categoryId",request.getParameter("categoryId"));
        request.setAttribute("id",3);//防指js出错
        String cacheKey=request.getParameter("categoryId");
        //取数据
        NewsService newService =new NewsServiceImpl();
        //处理分页操作
        PageBean news = newService.getPageBean("1", "3", "1");
        PageBean notices = newService.getPageBean("1", "3", "2");
        PageBean infors = newService.getPageBean("1", "3", "3");

        request.setAttribute("news",news);
        request.setAttribute("notices",notices);
        request.setAttribute("infors",infors);

        request.getRequestDispatcher("/index.jsp").forward(request,response);
    }
}
